def run(params:list[str]):
    #pip install xmltodict
    import xmltodict
    import json
    #pip install pandasql
    import pandas as pd
    from pandasql import sqldf
    import xml.etree.ElementTree as ET
    from ApiTools import apiTools, apiBase

    def map_csv(file_path):
        # 读取CSV文件
        df = pd.read_csv(file_path, sep=',')  # 如果是其他分隔符，比如制表符，可以将sep参数改为'\t'
        return df 


    sql_reg1=r'if.*?end|else.*?end'
    sql_reg2=r'select.*?from.*?where.*?;|delete.*?where.*?;|update.*?set.*?where.*?;|exec.*?;|create.*?;|drop.*?;'

    #reg=r'if.*?end|else.*?end'
    #reg=r'select.*?from.*?where.*?;|delete.*?where.*?;|update.*?set.*?where.*?;|exec.*?;'

    def map_sql(file_path):
        sections_data = pd.DataFrame(columns=['Block', 'Content'])
        #file_path="./scripts/300.sql"
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()
            content=content.lower()
            apiBase.lsExpress=[]
            content=apiBase.cut_all(content,apiBase.lsExpress,sql_reg1,sql_reg2,"----blockname")
            sections_data.append({'Block': "raw", 'Content': content})
            for i in range(len(apiBase.lsExpress)):            
                sections_data.append({'Block': f"block{i:05}", 'Content': apiBase.lsExpress[i]})
        
        # 创建DataFrame
        df = pd.DataFrame(sections_data)
        return df

    #pip install pandas openpyxl
    import pandas as pd
    
    # 读取Excel文件
    def map_excel(excel_file_path):
        df = pd.read_excel(excel_file_path)
        return df

    # 假设你有一个XML字符串
    # xml_data = """
    # <root>
    #     <element1>value1</element1>
    #     <element2>value2</element2>
    # </root>
    # """

    def map_xml(file_path):
        with open(file_path, 'r', encoding='utf-8') as file:
            xml_data = file.read()    
            # 使用xmltodict.parse将XML转换为字典
            dict_data = xmltodict.parse(xml_data)
            
            # 使用json.dumps将字典转换为JSON格式的字符串
            json_data = json.dumps(dict_data, indent=4, ensure_ascii=False)
            # 读取JSON数据到DataFrame
            df = pd.read_json(json_data)        
            return df
    
    # 假设您的JSON数据如下
    # json_data = '''
    # [
    #     {"name": "Alice", "age": 25, "city": "New York"},
    #     {"name": "Bob", "age": 30, "city": "San Francisco"}
    # ]
    # '''
    def map_json(file_path):
        with open(file_path, 'r', encoding='utf-8') as file:
            json_data = file.read()
            # 读取JSON数据到DataFrame
            df = pd.read_json(json_data)        
            return df

    import pdfplumber
    def map_pdf(file_path):
        # 创建一个空的DataFrame用于存储数据
        df = pd.DataFrame(columns=['Page', 'Content'])
        # 打开PDF文件
        with pdfplumber.open(file_path) as pdf:
            # 遍历每一页
            for page in pdf.pages:
                # 提取本页文本
                text = page.extract_text()
                df.loc[len(df)] = [page.page_number, text]                
        return df
        

    #pip install python-docx
    from docx import Document
    def map_docx(docx_path):
        # 加载docx文件
        doc = Document(docx_path)
        # 初始化一个空列表来保存章节数据
        df = pd.DataFrame(columns=['line', 'Content'])
        paragraphs = doc.paragraphs
        index=0
        for paragraph in paragraphs:
            content = paragraph.text
            df.loc[len(df)] = [index, content]
            index=index+1
        return df

    from docling.document_converter import DocumentConverter
    def  map_ppt(file_path): 
        # source = "https://arxiv.org/pdf/2408.09869"  # PDF path or URL
        converter = DocumentConverter()
        result = converter.convert(file_path)
        print(result.document.export_to_markdown()) 
        return df

    # 创建一个简单的DataFrame
    # df = pd.DataFrame({'name': ['Alice', 'Bob', 'Charlie'],
    #                    'age': [25, 30, 35],
    #                    'city': ['New York', 'Los Angeles', 'Chicago']})
    file_path = apiBase.argv(1,"$PROJECT_HOME/200testdata/测试.docx")
    file_path=file_path.replace("'","")
    if file_path.endswith(".csv"):
        df = map_csv(file_path)
    elif file_path.endswith(".txt"):
        df = map_csv(file_path)
    elif file_path.endswith(".sql"):
        df = map_sql(file_path)
    elif file_path.endswith(".ppt"): 
        map_ppt(file_path)
    elif file_path.endswith(".pptx"): 
        df = map_ppt(file_path)
    elif file_path.endswith(".docx"): 
        df = map_docx(file_path)
    elif file_path.endswith(".doc"): 
        df = map_docx(file_path)
    elif file_path.endswith(".pdf"):
        df = map_pdf(file_path)
    elif file_path.endswith(".xml"):
        df = map_xml(file_path)
    elif file_path.endswith(".json"):
        df = map_json(file_path)
    elif file_path.endswith(".xlsx"):
        df = map_excel(file_path)
    elif file_path.endswith(".xls"):
        df = map_excel(file_path)
    else:
        print("Unsupported file format")
    try:
        # 将DataFrame转换为JSON字符串``
        json_str = df.to_json(orient='records', force_ascii=False)
        print(json_str)
    finally:
        apiBase.close()
